package Bean;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckValue {
	
	public String getMD5(String password) throws NoSuchAlgorithmException {

		if (password == null || password.isEmpty()) {
			return null;
		}

		MessageDigest algorithm = MessageDigest.getInstance("MD5");

		algorithm.reset();
		algorithm.update(password.getBytes(), 0, password.length());

		return new BigInteger(1, algorithm.digest()).toString(16);
	}

	public boolean isEmail(String str) {
		String check = "^([a-z0-9A-Z]+[-|._]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?.)+[a-zA-Z]{2,}$";

		Pattern regex = Pattern.compile(check); 
		Matcher matcher = regex.matcher(str.trim()); 
		boolean isMatched = matcher.matches(); 

		if(isMatched) { 
			return true; 
		} else { 
			return false;
		} 
	}
}
